using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace GameLogic
{
    public class CellMaze : MonoBehaviour
    {
        // 使用字节存储四个方向是否可通过
        private byte passageFlags;

        // 方向标志位定义
        private const byte UP = 0b0001;    // 上
        private const byte DOWN = 0b0010; // 下
        private const byte LEFT = 0b0100; // 左
        private const byte RIGHT = 0b1000;// 右

        // 设置某个方向是否可通过
        public void SetPassage(Direction direction, bool isOpen)
        {
            if (isOpen)
            {
                passageFlags |= (byte)direction;
            }
            else
            {
                passageFlags &= (byte)~direction;
            }
        }

        // 检查某个方向是否可通过
        public bool IsPassable(Direction direction)
        {
            return (passageFlags & (byte)direction) != 0;
        }

        // 获取所有方向的状态
        public byte GetPassageFlags()
        {
            return passageFlags;
        }

        // 方向枚举
        public enum Direction : byte
        {
            Up = UP,
            Down = DOWN,
            Left = LEFT,
            Right = RIGHT
        }
    }
}
